home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / strategy / shanghai.000 / shanghai / shanghai-1.0 / menu.c < prev    next >
C/C++ Source or Header  |  1995-05-28  |  4KB  |  132 lines

  1. #include <time.h>
  2.  
  3. #include "board.h"
  4. #include "forms.h"
  5. #include "game.h"
  6. #include "gui.h"
  7. #include "shanghai.h"
  8.  
  9. static FD_copyright *fd_copyright = NULL;
  10.  
  11. void copyright_exitbutton(FL_OBJECT *ob,long data)
  12. {
  13.   if (fd_copyright->copyright->close_callback != NULL)
  14.     fd_copyright->copyright->close_callback
  15.       (fd_copyright->copyright,fd_copyright->copyright->close_data);
  16.   return;
  17. }
  18.  
  19. static int copyright_close(FL_FORM *fd_board,void *ptr)
  20. {
  21.   fl_hide_form(fd_copyright->copyright);
  22.   fl_free_form(fd_copyright->copyright);
  23.   fd_copyright = NULL;
  24.   if (--win_count == 0)
  25.     exit(0);
  26.   return(FL_IGNORE);
  27. }
  28.  
  29. void menu_shanghai(FL_OBJECT *ob, long data)
  30. {
  31.   enum {mAbout};
  32.  
  33.   switch (fl_get_menu(ob)-1) {
  34.   case mAbout:
  35.     if (fd_copyright)
  36.       XRaiseWindow(fl_get_display(),fd_copyright->copyright->window);
  37.     else {
  38.       fd_copyright = create_form_copyright();
  39.       win_count++;
  40.       fl_set_form_atclose(fd_copyright->copyright,copyright_close,NULL);
  41.       fl_set_form_minsize(fd_copyright->copyright,fd_copyright->copyright->w,
  42.               fd_copyright->copyright->h);
  43.       fl_set_form_maxsize(fd_copyright->copyright,fd_copyright->copyright->w,
  44.               fd_copyright->copyright->h);
  45.       fl_set_form_hotobject(fd_copyright->copyright,fd_copyright->exitbutton);
  46.       fl_show_form(fd_copyright->copyright,FL_PLACE_HOTSPOT,FL_FULLBORDER,
  47.            "Shanghai for X"); }
  48.     break;
  49.   default:
  50.     break; }
  51.   return;
  52. }
  53.  
  54. void menu_file(FL_OBJECT *ob, long data)
  55. {
  56.   enum {mNew,mRestart,mOpen,mClose,mQuit};
  57.  
  58.   switch (fl_get_menu(ob)-1) {
  59.   case mNew: {
  60.     int  seed;
  61.     FD_board * const fd_board = (FD_board *)data;
  62.     BoardRec * board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
  63.     default_isfastgame = board_rec->isfastgame;
  64.     free(board_rec);
  65.     srand(time(0)); do {seed = rand();} while (!seed);
  66.     board_rec = initialize_board_rec(fd_board,NULL,seed);
  67.     draw_all_tiles(board_rec);
  68.     break; }
  69.   case mRestart: {
  70.     FD_board * const fd_board = (FD_board *)data;
  71.     BoardRec * const board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
  72.     default_isfastgame = board_rec->isfastgame;
  73.     initialize_board_rec(fd_board,board_rec,board_rec->seed);
  74.     draw_all_tiles(board_rec);
  75.     break; }
  76.   case mOpen: {
  77.     FD_board * const fd_board = (FD_board *)data;
  78.     BoardRec * board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
  79.     default_isfastgame = board_rec->isfastgame;
  80.     new_board();
  81.     break; }
  82.   case mClose: {
  83.     FD_board *fd_board = (FD_board *)data;
  84.     if (fd_board->board->close_callback != NULL)
  85.       fd_board->board->close_callback(fd_board->board,
  86.                       fd_board->board->close_data);
  87.     break; }
  88.   case mQuit:
  89.     exit(0);
  90.   default:
  91.     break; }
  92.   return;
  93. }
  94.  
  95. void menu_options(FL_OBJECT *ob, long data)
  96. {
  97.   enum {mUndo,mPause,mFastMoves};
  98.  
  99.   switch (fl_get_menu(ob)-1) {
  100.   case mUndo: {
  101.     FD_board *fd_board = (FD_board *)data;
  102.     BoardRec *board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
  103.     game_undo_move(board_rec);
  104.     if (!board_rec->paused)
  105.       break; }
  106.     /* fall thru */
  107.   case mPause: {
  108.     FD_board *fd_board = (FD_board *)data;
  109.     BoardRec *board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
  110.     if (!!(board_rec->paused ^= 1)) {
  111.       fl_show_object(fd_board->pausebox);
  112.       if (board_rec->time > 0)
  113.     if ((board_rec->time -= time(0)) == 0)
  114.       board_rec->time = -1; }
  115.     else {
  116.       fl_hide_object(fd_board->pausebox);
  117.       if (board_rec->time < 0 && board_rec->matchcount)
  118.     if ((board_rec->time += time(0)) == 0)
  119.       board_rec->time = 1; }
  120.     update_info_box(board_rec);
  121.     break; }
  122.   case mFastMoves: {
  123.     FD_board *fd_board = (FD_board *)data;
  124.     BoardRec *board_rec = (BoardRec *)fd_board->board_frame->u_vdata;
  125.     board_rec->isfastgame ^= 1;
  126.     update_info_box(board_rec);
  127.     break; }
  128.   default:
  129.     break; }
  130.   return;
  131. }
  132.